package perucuy.logic;

import java.util.List;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.validator.DynaValidatorForm;
import org.apache.struts.action.Action;
import org.apache.log4j.Logger;
import perucuy.services.PartoService;

public class OpcionBrowserPartoAction extends Action {
    private static Logger log = Logger
            .getLogger(OpcionBrowserPartoAction.class);
    
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        DynaValidatorForm dynaValidatorForm = (DynaValidatorForm) form;
        String boton = dynaValidatorForm.getString("boton");
        String textobuscar = dynaValidatorForm.getString("txtBuscar");
        String tipobuscar = dynaValidatorForm.getString("txtTipoBuscar");
        if (boton.toUpperCase().equals("NUEVO")) {
            return mapping.findForward("agregar");
        }
        if (boton.toUpperCase().equals("BUSCAR")) {
            PartoService partosrvc = new PartoService();
            //Se procede a obtener el listado de albergados
            List lista = partosrvc.getPartos(Integer.parseInt(tipobuscar), textobuscar);
            log.debug("Dato de la lista "+lista);
            assert lista != null:"no se obtuvo lista. filtro=";
            if (lista != null && lista.size()>0)request.setAttribute("listadoParto", lista);
            
            return mapping.findForward("buscar");
        }
        return mapping.findForward("success");
    }
}
